package com.xuecheng.content.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Value("${course.publish.exchange}")
    private String exchange;

    @Value("${course.publish.queue}")
    private String queue;

    @Value("${course.publish.routing-key}")
    private String routingKey;

    @Bean("coursePubEx")
    public DirectExchange simpleExchange() {
        return new DirectExchange(exchange, true, false);
    }

    @Bean("coursePubQueue")
    public Queue simpleQueue() {
        return QueueBuilder.durable(queue).build();
    }

    @Bean
    public Binding errorBinding(Queue coursePubQueue, DirectExchange coursePubEx) {
        return BindingBuilder.bind(coursePubQueue).to(coursePubEx).with(routingKey);
    }
}
